from typing import *


class Solution:

    def countPairs(self, coordinates: List[List[int]], k: int) -> int:
        s = dict()
        ans = 0
        for x, y in coordinates:
            for i in range(k + 1):
                a, b = i ^ x, (k - i) ^ y
                ans += s.get((a, b), 0)
            if (x, y) not in s:
                s[(x, y)] = 1
            else:
                s[(x, y)] += 1
        return ans


class Solution:

    def countPairs(self, coordinates: List[List[int]], k: int) -> int:
        s = DefaultDict(tuple())
        ans = 0
        for x, y in coordinates:
            for i in range(k + 1):
                a, b = i ^ x, (k - i) ^ y
                ans += s[(a, b)]
            s[(a, b)] += 1
        return ans